const mapCurrencyDecimals = new Map([
    ['SLP', 2],
    ['BSC-USD', 2],
    ['PGX', 4],
    ['VIS', 4],
]);

export default class NumberTool {
    static format = (value, token = '', decimals?: number): string => {
        const precision =
            decimals !== undefined ? decimals : mapCurrencyDecimals.get(token.toUpperCase());
        if (value != undefined) {
            return parseFloat(value)
                .toFixed(precision || precision === 0 ? precision : 2)
                .replace(/\d(?=(\d{3})+\.)/g, '$&,');
        }

        return '';
    };

    static dollar = (value, token): string => {
        if (value != undefined && value != '') {
            return '$' + this.format(value, token);
        }

        return '';
    };

    static roundUp = (value: number): number => {
        if(value % 1 != 0) {
            return value + 1;
        }

        return value;
    }
}
